function detectCycle(node) {
  let set = new Set()
  while (node && node.next) {
    if (set.size && set.has(node)) {
      return true
    }
    set.add(node)
    node = node.next
  }
  return false
}

function detectCycle(node) {
  let fast = node
  let slow = node
  while (fast && slow && fast.next) {
    fast = fast.next.next
    slow = slow.next
    if (fast === slow) return true
  }
  return false
}
